﻿package com.mypaper.elem;

public class PairElement extends DataElement{
	/*
	 * 空闲时间的起始时间，有序对表示
	 */
	public float start;
	public float end;
	
	public PairElement(){
		start = 0;
		end = 0;
	}
	
	public PairElement(float x, float y){
		start = x;
		end = y;
	}
	
	public PairElement(PairElement otherElement){
		start = otherElement.start;
		end = otherElement.end;
	}
	
	public void setNum(float x, float y){
		start = x;
		end = y;
	}
	
	public float getStart(){
		return start;
	}
	
	public float getEnd(){
		return end;
	}
	
	public boolean equals(DataElement otherElement){
		PairElement temp = (PairElement)otherElement;
		return (start == temp.start && end == temp.end);
	}
	
	
	public boolean equalStart(float end){
		if(this.start==end)
			return true;
		else 
			return false;
	}
	
	public boolean equalEnd(float start){
		if(this.end==start)
			return true;
		else 
			return false;
	}
	
	public int compareTo(DataElement otherElement){
		PairElement temp = (PairElement)otherElement;
		if(start < temp.start){
			temp=null;
			return -1;
		}
		if(start > temp.start){
			temp=null;
			return 1;
		}
		return 0;
	}
	public DataElement properSlot(DataElement otherElement){
		//找到第一个满足要求的空闲段，可插入任务
		PairElement temp = (PairElement)otherElement;
		if(end-Math.max(start,temp.start)>= temp.end-temp.start)
			return temp;
		else
			return null;
	}
	
	public DataElement properSlotMoveTo(float start, float end, float weight){
		PairElement temp=new PairElement(start, end);
		if(Math.min(temp.end, this.end)-Math.max(temp.start, this.start)>=weight){
			return temp;
		}else{
			return null; 
		}
	}
	
	public void makeCopy(DataElement otherElement){
		//将其他数据复制给本身
		PairElement temp = (PairElement)otherElement;
		start = temp.start; 
		end = temp.end;
	}
	
	public DataElement getCopy(){
		//将本身复制给其他数据
		PairElement temp = new PairElement(start, end);
		return temp;
	}
	
	public String toString(){
		return String.valueOf("("+start+","+end+")");
	}
}
